import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';

import '../../../../hj_utils/api_service/mine_service.dart';
import '../../../../hj_utils/global.dart';

class SearchUserCell extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SearchUserCellState();
  }
}

class _SearchUserCellState extends State<SearchUserCell> {
  bool get isFollow => false;
  bool loading = false;

  Future _onFollowUser() async {
    bool followStatus = !isFollow;
    if (loading) return;
    loading = true;
    setState(() {});

    bool result = await MineService.getFollow(-1, followStatus);
    if (result) {
      showToast(followStatus ? '关注成功' : '取消关注');
    }
    loading = false;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 60,
      child: Row(
        children: [
          NetworkImageLoader(
            imageUrl: "",
            borderRadius: 60,
            width: 60,
            height: 60,
          ),
          12.sizeBoxW,
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "",
                  maxLines: 1,
                  style: textStyle(12, Color(0xE5FFFFFF), FontWeight.w500),
                ),
                Text(
                  "3.3w点赞  3.3w作品  3.3w粉丝",
                  maxLines: 1,
                  style: textStyle(12, Color(0x8CFFFFFF), FontWeight.w400),
                ),
              ],
            ),
          ),
          6.sizeBoxW,
          GestureDetector(
            onTap: _onFollowUser,
            child: Container(
              height: 26,
              width: 62,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: Color(0xFFFD2D55),
                borderRadius: BorderRadius.circular(4),
              ),
              child: loading
                  ? _loadingView()
                  : Text(
                '关注Ta',
                style: TextStyle(
                  fontSize: 12,
                  fontWeight: FontWeight.w500,
                  color: Colors.white,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _loadingView() {
    return CupertinoActivityIndicator(
      color: Colors.white,
      radius: 8,
    );
  }
}
